package com.rocksea.app.weight;

import android.content.Context;
import android.graphics.Canvas;
import android.view.View;

import com.rocksea.app.rslib.JyDoc;
import com.rocksea.app.utils.UiUtils;

/**
 * @author Administrator
 * @date 2017/11/28
 */

public class StaticLoadCurveView extends View
{
    private int sw;
    private int curveMode;
    private JyDoc jyDoc;
    private StaticLoadCurveFormat format;

    public static final int QS = 1;
    public static final int S_LGT = 2;
    public static final int S_LGQ = 3;


    public StaticLoadCurveView(Context context,StaticLoadCurveFormat format,int code)
    {
        super(context);
        sw = UiUtils.getDisPlayWight();
        this.format = format;
        curveMode = code;
        try
        {
            jyDoc = new JyDoc(format.totalCounts,format.json);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public StaticLoadCurveView(Context context) {
        super(context);
    }

    @Override
    protected void onDraw(Canvas canvas)
    {
        super.onDraw(canvas);
        jyDoc.setImageHeight(sw);
        jyDoc.setImageWidth(sw);
        jyDoc.setIsGroundTest(format.isGroundTest);
        jyDoc.setIsUp(format.isUp);
        if (format.boardArea>0)
            jyDoc.setBoardArea(format.boardArea);
        try {
            switch (curveMode)
            {
                case QS:
                    jyDoc.getQsImage(canvas);
                    break;
                case S_LGQ:
                    jyDoc.getSlgQImage(canvas);
                    break;
                case S_LGT:
                    jyDoc.getSlgtImage(canvas);
                    break;
            }
        }catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public static class StaticLoadCurveFormat
    {
        public String json;
        private boolean isGroundTest = false;
        private boolean isUp = false;
        private float boardArea;
        private int totalCounts;
        public StaticLoadCurveFormat(String json,int totalCounts, float boardArea, String testName)
        {
            this.json = json;
            this.totalCounts = totalCounts;
            this.boardArea = boardArea;
            if (testName == null)
                return;
            if (testName.contains("拔"))
            {
                isUp = true;
            }
            if (testName.contains("复合"))
            {
                isGroundTest = true;
            }
        }
    }
}
